import com.qf.dao.UserDao;
import com.qf.entity.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;

public class HelloMybatis {

    @Test
    public void test01() throws IOException {
        //1.获取mybatis配置文件流对象
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");

        //2.构建sqlsession工厂
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);

        //3.获取数据库连接对象
        SqlSession sqlSession = build.openSession();

        //4.通过连接对象获取接口实现类对象（通过反射原理）
        UserDao userDao = sqlSession.getMapper(UserDao.class);
        User user = userDao.selectUserById(3);
        System.out.println(user);


    }
}
